package com.zr.serviceimpl;

import java.text.SimpleDateFormat;
import java.util.Date;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.zr.dao.InsertNewDisstationDao;
import com.zr.model.Cstationtype;
import com.zr.model.Cuser;
import com.zr.service.InsertNewDisstationService;

@Service("insertNewDisstationService")
public class InsertNewDisstationServiceImpl<T> implements InsertNewDisstationService<T>{

	@Resource
	private InsertNewDisstationDao insertNewDisstationDao;

	@Override
	public int getStataionExistsOrNot(String disname) {
		return insertNewDisstationDao.getStataionExistsOrNot(disname);
	}

	@Override
	public void insertNewDisstation(String cuname, int cuid, String disname,Cstationtype cstationtype, int uid, String disscope,
			double disprice, int instation) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date date = new Date();
		String time = sdf.format(date);
		StringBuffer infos = new StringBuffer();
		infos.append("编号为");
		infos.append(cuid);
		infos.append("的用户");
		infos.append(cuname);
		infos.append("在");
		infos.append(time);
		infos.append("增加了名称为");
		infos.append(disname);
		infos.append("的配送点");
		String info = infos.toString();
		Cuser cuser = insertNewDisstationDao.getUserByUid(uid);
		insertNewDisstationDao.InsertNewDisstation(disname,cstationtype,cuser, disscope, disprice, instation);
		int instations = insertNewDisstationDao.getNewStationIdByDisname(disname);
		insertNewDisstationDao.updateUserByUidAndDisid(uid,instations);
		insertNewDisstationDao.insertInfoIntoLog(time, cuname, cuid, info);
		
	}



	@Override
	public Cstationtype getDistypeByInfo(String distype) {
		
		return insertNewDisstationDao.getDistypeByInfo(distype);
	}
	
	
	
	
}
